// Copyright 2013 Stephane SOPPERA
//
// This file is part of 3ds-image-uploader.
//
// 3ds-image-uploader is free software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// 3ds-image-uploader is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with 3ds-image-uploader.  If not, see <http://www.gnu.org/licenses/>.

var attrRE = /([^$]|^)\$\{([a-zA-Z_0-9]+)\}/g

function apply(str, vals) {
    return str.replace(attrRE, function (full, firstChar, id) {
	if (vals.hasOwnProperty(id))
	    return firstChar + vals[id];
	else
	    return full;
    });
}

exports.apply = apply;
